const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function patchLogin() {
  try {
    // 检查数据库中的refreshToken列类型
    console.log('正在修复登录问题...');
    
    // 将用户的emailVerified设置为true，确保可以登录
    const updatedUser = await prisma.user.update({
      where: { username: 'admin' },
      data: { 
        emailVerified: true
      }
    });
    
    console.log('用户邮箱验证状态已更新:', updatedUser.emailVerified);
    
    // 尝试临时修复refreshToken问题
    await prisma.$executeRaw`ALTER TABLE Secrets MODIFY refreshToken VARCHAR(255)`;
    console.log('已更新refreshToken列类型为VARCHAR(255)');
    
    // 确认修改成功
    const secretsColumns = await prisma.$queryRaw`DESCRIBE Secrets`;
    const refreshTokenColumn = secretsColumns.find(col => col.Field === 'refreshToken');
    console.log('refreshToken列现在是:', refreshTokenColumn.Type);
    
    console.log('修复完成，请尝试重新登录');
  } catch (error) {
    console.error('修复失败:', error);
  } finally {
    await prisma.$disconnect();
  }
}

patchLogin(); 